package both;
import java.util.ArrayList;

/**
 *
 * @author Timothy Woodford
 */

public class Team {

    private final String name;
    private final ArrayList<Contestant> teamMembers = new ArrayList<>();
    private int numCorrect;
    private double teamScore;

    public Team(String teamName) {
        name = teamName;
    }

    /**
     * Increase the count of the members who got the last question correct by 1
     */

    public void tickNumCorrect() {
        numCorrect++;
    }

    

    /**
     * Resets the correct answer counter to zero.  Always call *before* processing
     * a question.
     */
    public void resetNumCorrect() {
        numCorrect = 0;
    }

    

    /**
     * Find the percentage of the team that got the last question correct, based
     * on the the correct answer counter and number of currently registered
     * team members.
     *
     * @return Percent who correctly answered previous question
     */
    public double percentageCorrect() {
        return proportionCorrect()*100;
    }

    

    /**
     * Proportion (not percentage) of contestants with correct answers
     */
    private double proportionCorrect() {
        return ((double) numCorrect)/teamMembers.size();
    }

    

    /**
     * Update the score of the team based on the correct answer counter
     * @param lastQuestion
     */
    public void updateScore(Question lastQuestion) {  
        if(lastQuestion.getPointValue()!=0){
            teamScore += proportionCorrect()*lastQuestion.getPointValue();
        } else {
            teamScore += proportionCorrect()*Game.getDefaultPointValue();
        }
    }

    /**
     * Add a new member to the team
     * @param member The new member
     */
    public void addMember(Contestant member) {
        teamMembers.add(member);
    }

    /**
     * Remove the member from the team
     */
    public void removeMember(Contestant member) {
        teamMembers.remove(member);
    }

    /**
     * @return the team's name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the team's score
     */
    public double getTeamScore() {
        return teamScore;
    }

    /**
     * @return a list of the team members
     */
    public ArrayList<Contestant> getTeamMembers() {
        return teamMembers;
    }
}



